﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Truextend.Common.Data;
using Truextend.Training.Model.Entities;

namespace Truextend.Training.Service
{
    public class BaseService
    {
        public void ExecuteManager(Action<IUnitOfWork> coreMethod, Action postCommit = null)
        {
            var uow = new EFUnitOfWork<TrainingEntities>();
            var commited = false;
            try
            {
                uow.Start();
                coreMethod(uow);
                uow.End();
                commited = true;
                if (postCommit != null) postCommit();
            }
            catch (Exception ex)
            {
                if (!commited) uow.Rollback();
                throw;
            }
        }
    }
}
